﻿using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace echuCMS
{
    public partial class FormCityAdminManage : Form
    {
        private BindingSource bsSalesMan = new BindingSource();
        public FormCityAdminManage()
        {
            InitializeComponent();
        }
        private void FormCityAdminManage_Load(object sender, EventArgs e)
        {
            dataGridViewSalesMan.AutoGenerateColumns = false;
        }
        private void FormCityAdminManage_Shown(object sender, EventArgs e)
        {
            //加载城市
            getCity();
        }

        private void getCity()
        {
            List<City> cityList = SalesManService.getCity();
            cityList.Insert(0, new City() { id = 0, city = "请选择" });
            this.combCity.DataSource = cityList;
            this.combCity.DisplayMember = "CityName";
            this.combCity.ValueMember = "CityID";
        }

        private void dataGridViewSalesMan_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.ColumnIndex == 1 && e.Value is City)
            {
                e.Value = (e.Value as City).city;
            }
        }
        /// <summary>
        /// 选择的城市列出当地的业务员
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void combCity_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (combCity.SelectedIndex>0)
            {
                double cityId = double.Parse(combCity.SelectedValue.ToString());
                List<SalesMan> salesManList = SalesManService.getSalesManByCityId(cityId);
                bsSalesMan.DataSource = salesManList;
                this.dataGridViewSalesMan.DataSource = bsSalesMan;
            }
        }

       
    }
}
